package com.rdgk.newtech.controller;

import com.alibaba.fastjson.JSONObject;
import com.rdgk.newtech.service.FileService;
import com.rdgk.newtech.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * 附件
 */
@RestController
@RequestMapping("/file")
public class FileController {

	@Autowired
	private FileService service;

	/**
	 * 查询列表
	 */
	@PostMapping("/listFile")
	public JSONObject listFile(HttpServletRequest request) {
		System.out.println(CommonUtil.request2Json(request));
		return service.listFile(CommonUtil.request2Json(request));
	}



	/**
	 * 新增
	 */
	@PostMapping("/addFile")
	public JSONObject addFile(HttpServletRequest request) {
		return service.addFile(request);
	}



	/**
	 * 修改
	 */
	@PostMapping("/deleteFileById")
	public JSONObject deleteFileById(HttpServletRequest request) {
		return service.deleteFileById(CommonUtil.request2Json(request));
	}



	/**
	 * 上传文件
	 */
	@PostMapping("/uploadFile")
	public JSONObject uploadFile(HttpServletRequest request,MultipartFile file) {
		return service.uploadFile(request,file);
	}
}
